package com.briup.test;

import com.briup.Dao.StudentMapperDynamic;
import com.briup.pojo.Student;
import com.briup.uitls.SqlSessionFactoryUtils;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.junit.Test;

import java.util.List;

public class SelectDynamic {
    //用if动态传递参数查询测试
    @Test
    public void getStudentDynamic(){
        SqlSessionFactory sqlSessionFactory = SqlSessionFactoryUtils.getSqlSessionFactory();
        SqlSession sqlSession = sqlSessionFactory.openSession();
        StudentMapperDynamic mapper = sqlSession.getMapper(StudentMapperDynamic.class);
        List<Student> list = mapper.getStudentDynamic(new Student(null, "", "女", ""));
        for (Student s :list ) {
      System.out.println(s);
        }

    }
    //测试trim标签
    @Test
    public void getStudentDynamicByTrim(){
        SqlSessionFactory sqlSessionFactory = SqlSessionFactoryUtils.getSqlSessionFactory();
        SqlSession sqlSession = sqlSessionFactory.openSession();
        StudentMapperDynamic mapper = sqlSession.getMapper(StudentMapperDynamic.class);
        List<Student> list = mapper.getStudentDynamicByTrim(new Student(null, "", "男", ""));
        for (Student s : list ) {
      System.out.println(s);
        }
    }

    //测试choose
    @Test
    public void getStudentDynamicByChoose(){
        SqlSessionFactory sqlSessionFactory = SqlSessionFactoryUtils.getSqlSessionFactory();
        SqlSession sqlSession = sqlSessionFactory.openSession();
        StudentMapperDynamic mapper = sqlSession.getMapper(StudentMapperDynamic.class);
        List<Student> studentDynamicByChoose = mapper.getStudentDynamicByChoose(new Student(null, null, "男", null));
        for (Student s :studentDynamicByChoose ) {
      System.out.println(s);
        }

    }
}
